<?php defined('InShopNC') or exit('Access Invalid!');?>

<div class="page">
  <div class="fixed-bar">
    <div class="item-title">
      <h3><?php echo $lang['activity_index_manage'];?></h3>
      <ul class="tab-base">
        <li><a href="index.php?act=goods_templates&op=index"><span>活动模板管理</span></a></li>
        <li><a href="index.php?act=goods_templates&op=addGt_class"><span>添加活动模板</span></a></li>
        <li><a href="index.php?act=goods_templates&op=goods_templates_list"><span>模板商品管理</span></a></li>
        <li><a href="javascript:;" class="current"><span>添加模板商品</span></a></li>
      </ul>
    </div>
  </div>
  <div class="fixed-empty"></div>
  <form id="add_form" method="post" enctype="multipart/form-data">
    <input type="hidden" name="form_submit" value="ok" />
    <input type="hidden" name="gs_tp_id" value="<?php echo $output['goods_templates_info']['gs_tp_id'];?>">
    <table class="table tb-type2">
      <tbody>
      <tr class="noborder">
          <td colspan="2" class="required"><label class="validation" for="activity_title">请选择模板：</label></td>
        </tr>
        <tr class="noborder">
          <td class="vatop rowform">
			<select name="gt_class_id" class="querySelect">
                	<option value="">--请选择--</option>
					<?php if(!empty($output['gt_class_list'])) { ?>
	          		<?php foreach($output['gt_class_list'] as $key =>$val) {?>
	          		<option value="<?php echo $val['gt_class_id'];?>" <?php echo $output['goods_templates_info']['gt_class_id'] == $val['gt_class_id']?'selected':'';?>><?php echo $val['gt_class_name'];?></option>
	          		<?php } } ?>
                </select>
			</td>
          
        </tr>
      
       <tr class="noborder">
          <td colspan="2" class="required"><label class="validation" for="activity_title">是否商品：</label></td>
        </tr>
        <tr class="noborder">
          	
          	<td style="width: 30px; font-size: 16px;">
          	是<input type="radio" name="is_goods" id="is_goods" value="1" class="checkitem" <?php if($output['goods_templates_info']['is_goods']=='1'){?>checked<?php }?>>
          	否<input type="radio" name="is_goods" value="0" class="checkitem" <?php if($output['goods_templates_info']['is_goods']=='0'){?>checked<?php }?>>
          	</td>
               
        </tr>
        
        <tr class="noborder goods_size" style="display: none;">
          <td colspan="2" class="required"><label class="validation" for="activity_title">商品模板大图还是小图：</label></td>
        </tr>
        <tr class="noborder goods_size_choose" style="display: none;">
          	
          	<td style="width: 30px; font-size: 16px;">
          	大<input type="radio" name="goods_size"  value="1" class="checkitem" <?php if($output['goods_templates_info']['goods_size']=='1'){?>checked<?php }?>>
          	小<input type="radio" name="goods_size" value="0" class="checkitem" <?php if($output['goods_templates_info']['goods_size']=='0'){?>checked<?php }?>>
          	</td>
               
        </tr>

        <tr class="noborder goods_choose"  style="display: none;">
          <td colspan="2"><label class="validation" for="activity_title">选择商品：</label></td>
        </tr>
        <tr class="noborder goods_search"  style="display: none;">
          	
          	<td style="width: 30px; font-size: 16px;">
          	<input id="like_name" name='goods_name' value="" placeholder="输入商品名称" />
          	<button id='search'>查询商品</button>
          	</td>
               
        </tr>
        
        <tr class='goods_name' style="display: none;">
        <td><input type="text" style="width: 120px;" name="goods_id" value="<?php echo ($output['goods_templates_info']['goods_id']);?>" readonly="readonly" /></td>
        </tr>
        <tr class='goods_per_next' style="display: none;">
        	<td id="about_goods" style="width: 90%;height: 240px; display:none;">
        		<span id="goods_info">
    			</span>
        		<span><button id='pre_search'>上一页</button><input type="hidden" name="stip" id="skip" value="0" /><button id='next_search'>下一页</button></span>
        	</td>
        </tr>

		<tr class="noborder">
          <td colspan="2" class="required"><label class="validation" for="activity_title">是否代金券：</label></td>
        </tr>
        <tr class="noborder">
          	
          	<td style="width: 30px; font-size: 16px;">
          	是<input type="radio" name="is_voucher" id="is_voucher" value="1" class="checkitem" <?php if($output['goods_templates_info']['is_voucher']=='1'){?>checked<?php }?>>
          	否<input type="radio" name="is_voucher" value="0" class="checkitem" <?php if($output['goods_templates_info']['is_voucher']=='0'){?>checked<?php }?>>
          	</td>
               
        </tr>

        <!-- 20161228周家财修改 -->
        <tr class="noborder voucher_list" style="display: none;">
          <td colspan="2"><label  for="activity_type">代金券列表:</label></td>
        </tr>
        <tr class="noborder choose_voucher" style="display: none;">
          <td class="vatop rowform">
			<select name="voucher_t_id" class="querySelect">
                	<option value="">--请选择--</option>
					<?php if(!empty($output['voucher_templates_list'])) { ?>
	          		<?php foreach($output['voucher_templates_list'] as $vt_list) {?>
	          		<option value="<?php echo $vt_list['voucher_t_id'];?>" <?php echo $output['goods_templates_info']['voucher_t_id'] == $vt_list['voucher_t_id']?'selected':'';?>><?php echo $vt_list['voucher_t_title'].'-满'.$vt_list['voucher_t_limit'].'减'.$vt_list['voucher_t_price'];?></option>
	          		<?php } } ?>
                </select>
			</td>
          
        </tr>
        
        <tr class="noborder">
          <td colspan="2" class="required"><label class="validation" for="activity_title">是否广告图：</label></td>
        </tr>
        <tr class="noborder">
          	
          	<td style="width: 30px; font-size: 16px;">
          	是<input type="radio" name="is_adv" id="is_adv" value="1" class="checkitem" <?php if($output['goods_templates_info']['is_adv']=='1'){?>checked<?php }?>>
          	否<input type="radio" name="is_adv" value="0" class="checkitem" <?php if($output['goods_templates_info']['is_adv']=='0'){?>checked<?php }?>>
          	</td>
               
        </tr>
        
        <tr class="noborder adv_tips" style="display: none;">
          <td colspan="2" class="required"><label class="validation" for="activity_title">广告图大小：</label></td>
        </tr>
        <tr class="noborder adv_choose" style="display: none;">	
          	<td style="width: 30px; font-size: 16px;">
              	大<input type="radio" name="adv_size" id="adv_size" value="1" class="checkitem" <?php if($output['goods_templates_info']['adv_size']=='1'){?>checked<?php }?>>
              	小<input type="radio" name="adv_size" value="0" class="checkitem" <?php if($output['goods_templates_info']['adv_size']=='0'){?>checked<?php }?>>
          	</td>
               
        </tr>
        <tr class="noborder adv_tips" style="display: none;">
          <td colspan="2" class="required"><label class="validation" for="activity_title">广告图之后商品个数：</label></td>
        </tr>
        <tr class="noborder adv_choose" style="display: none;">	
          	<td style="width: 30px; font-size: 16px;">
              	大商品图片个数:<input type="text" name="goods_big_num"  value="<?php echo ($output['goods_templates_info']['goods_big_num']);?>" >
              	小商品图片个数:<input type="text" name="goods_small_num" value="<?php echo ($output['goods_templates_info']['goods_small_num']);?>" >
          	</td>
               
        </tr>
        
        <tr>
          <td colspan="2" class="required"><label >上传模板图片:</label></td>
        </tr>
        
        <tr class="noborder">
          <td class="vatop rowform"> <span class="type-file-box"  style="height: auto;">
          <?php if($output['goods_templates_info']['gs_tp_image']!=null || !empty($output['goods_templates_info']['gs_tp_image'])){?> 
            <img alt="" id='pic_src' style="width: 150px; height: auto;" src="<?php echo (UPLOAD_SITE_URL.'/'.GT_TEMPLATES.'/'.$output['goods_templates_info']['gs_tp_image']);?>">
            <?php }?>
            <input type="hidden" name='pic_check' value="0" />
            <input type="file" name='gs_tp_image' size="30" >
            <!-- <input type="file" class="type-file-file" name='gs_tp_image' size="30" /> -->
           </span> </td>
          <td class="vatop tips">列表商品不需要上传模板图片</td>
        </tr>
        
        <tr class="noborder">
          <td colspan="2" ><label class="validation" for="activity_title">图片宽度：</label></td>
        </tr>
        <tr class="noborder">
          	
          	<td >
          	<input id="like_name" name='gs_tp_image_width' value="<?php echo ($output['goods_templates_info']['gs_tp_image_width']);?>" placeholder="输入图片宽度" />
          	</td>
               
        </tr>
        
        <tr class="noborder">
          <td colspan="2" ><label class="validation" for="activity_title">图片高度：</label></td>
        </tr>
        <tr class="noborder">
          	
          	<td >
          	<input id="like_name" name='gs_tp_image_height' value="<?php echo ($output['goods_templates_info']['gs_tp_image_height']);?>" placeholder="输入图片高度" />
          	</td>
               
        </tr>
        
        
        
      </tbody>
      <tfoot>
        <tr class="tfoot">
          <td colspan="2"><a  href="JavaScript:void(0);" class="btn" id="submitBtn"><span><?php echo $lang['nc_submit'];?></span></a></td>
        </tr>
      </tfoot>
    </table>
  </form>
</div>
<link type="text/css" rel="stylesheet" href="<?php echo RESOURCE_SITE_URL."/js/jquery-ui/themes/ui-lightness/jquery.ui.css";?>"/>
<script src="<?php echo RESOURCE_SITE_URL."/js/jquery-ui/jquery.ui.js";?>"></script> 
<script src="<?php echo RESOURCE_SITE_URL."/js/jquery-ui/i18n/zh-CN.js";?>" charset="utf-8"></script> 
<script type="text/javascript">
//按钮先执行验证再提交表单
/* $("#submitBtn").click(function(){
    var is_goods=$('input[name="is_goods"]').val();
     var is_adv=$('input[name="is_adv"]').val();
     var is_voucher=$('input[name="is_voucher"]').val();
     //$('input[name="deliver_company"]').val(company);
     if((is_voucher==1 && is_adv==1)||(is_voucher==1 && is_goods==1)||(is_adv==1 && is_goods==1)){
     	window.location.reload();
     	return false;
     }
} */

$(function(){
	var pic_src=$('#pic_src').attr('src');
	 //alert(pic_src);
	 var match=/.(gif|jpg|jpeg|png|gif|jpg|png)$/;
    if(match.test(pic_src)){
        $('input[name="pic_check"]').val(1);
    }
});

$(function(){
	$("#submitBtn").click(function(){//window.location.reload();
		if($("#add_form").valid()){
    		$("#add_form").submit();
		}
    	
    });
});

$('#search').click(function(){
	var skip=0;
    //alert(skip);
	var goods_name=$("#like_name").val();
	if(goods_name==''){
		goods_name=0;
	}
	
    $("#about_goods").show();
    get_goods(goods_name,skip); 
    return false;
	
});


$('#pre_search').click(function(){
	alert($("#skip").val());
    var skip=parseInt($("#skip").val())-1;
    //alert(skip);
     if(skip<0){
		alert("这是第一页了");return false;
    }
    alert(skip);
	var goods_name=$("#like_name").val();
	if(goods_name==''){
		goods_name=0;
	}
	get_goods(goods_name,skip) ;
	return false;
	
});


$('#next_search').click(function(){
    var skip=parseInt($("#skip").val())+1;
    //skip=skip+1;
    //alert(skip);
	var goods_name=$("#like_name").val();
	if(goods_name==''){
		goods_name=0;
	}
	get_goods(goods_name,skip) ;
	
	return false;
	
});

function get_goods(goods_name,skip){
	$.ajax({
	       type: "post",
	       data:{goods_name:goods_name,skip:skip},
	       url: "index.php?act=goods_templates&op=goods_list",
	       dataType: "json",
	       success: function (data) {
	    	   $("#goods_info").empty();//return false;
		       var html='';
		       if(data.status==1){
				var goods_list=data.goods_list;
				var length = goods_list.length;
				for(var i=0;i<length;i++){
					var name=goods_list[i].goods_name.substring(0,18); 
					html +='<span style="float:left">';
					html +='<img alt="'+goods_list[i].goods_name+'" style="cursor: pointer;" class="goods_image" data="'+goods_list[i].goods_id+'" src="'+goods_list[i].goods_image+'"/>';    					
				    html+='<b style="display:block">'+name+'...</b>';
					html +='</span>';
			  	}
				setTimeout(function () { 
					$('#goods_info').html(html);

					$(".goods_image").click(function(){
						$('input[name="goods_id"]').val($(this).attr("data"));
					});
					 
			    }, 1000);

		   		}
		       $("#skip").val(data.skip);
		       
		   }

	    });
}

function bind_goods(){
	$(".goods_image").on("click",function(){
		alert($(this).attr(data));
	});
}

$("#is_goods").click(function(){

	$('.goods_choose').show();
	$('.goods_search').show();
	$('.goods_name').show();
	$('.goods_per_next').show();
	$('.goods_size').show();
	$('.goods_size_choose').show();
});

$("#is_voucher").click(function(){
	
	$('.voucher_list').show();
	$('.choose_voucher').show();
	
});

$("#is_adv").click(function(){
	$('.adv_tips').show();
	$('.adv_choose').show();
});



</script>